package com.northpool.stpclient.demo;

import com.northpool.stpclient.StpClient;
import com.northpool.stpclient.bean.complex.ComplexQueryRequest;
import com.northpool.stpclient.bean.task.response.ComplexQueryResponseBean;
import com.northpool.stpclient.bean.tile.dataset.QueryDataSet;
import com.northpool.stpclient.bean.tile.dataset.SpatialRelation;
import com.northpool.stpclient.bean.tile.dataset.SqlDataSet;
import com.northpool.stpclient.modules.geoprocess.complex.IComplexOperator;
import org.apache.commons.lang3.ArrayUtils;

import java.io.UnsupportedEncodingException;
import java.util.LinkedList;
import java.util.List;

public class ComplexQueryDemo {
    // stpserver访问地址
    public static final String host = "http://127.0.0.1:8088/stpserver";
    // 构建客户端
    public static StpClient client = new StpClient(host);

    public static void main(String[] args) throws UnsupportedEncodingException {

        IComplexOperator complexOperator = client.complexOperator();

        ComplexQueryRequest request = new ComplexQueryRequest();
        request.setMinArea(1000D);
        request.setMaxArea(10000000D);
        List<QueryDataSet> datasetList = new LinkedList<>();
        QueryDataSet queryDataSet = new QueryDataSet();
        SqlDataSet ds = new SqlDataSet();
        ds.setDataSourceId("pg13");
        ds.setTableName("public.dltbcut");
        ds.setSqlFilter("dlmc in ('旱地')");

        queryDataSet.setSource(ds);
        queryDataSet.setRelation(SpatialRelation.Relation.self);
        datasetList.add(queryDataSet);
        request.setDatasets(datasetList);

        ComplexQueryResponseBean res = complexOperator.startComplexQuery(request);
        System.out.println(ArrayUtils.toString(res.getIds()));
    }
}
